package copy.meta;

import copy.application.Application;
import copy.meta.impl.ParseEasycopyMetaDataStrategyHandler;
import copy.pojo.MethodMeta;
import copy.scan.ScanStrategy;

import java.util.HashMap;
import java.util.Map;

public abstract class AbsParseMetaData implements ParseEasyCopyMetaData {

    // 全限定类名 和 其中方法的元数据信息
    public static Map< String, Map<String, MethodMeta> > interfaceMetaDataMap = new HashMap<>();


   protected Application application;

   public void init(){
        //加载上下文容器
        application = Application.getScanSingleBean();
        //加载类
        for (String className : ScanStrategy.easycopyMap.keySet()) {
            System.out.println("正在处理的classNAme: " + className);
            try {
                Map<String, MethodMeta> methodMetaMap = interfaceMetaDataMap.putIfAbsent(className, new HashMap<>());
                if (methodMetaMap != null){
                    throw new Exception("重复加载字节码文件(全限定名称重复):"+className);
                }
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    //控制整个流程
    public void process() throws ClassNotFoundException {
       init();
        System.out.println("=====================START========================");
        System.out.println("AbsParseMetaData已经启动:正在解析接口元数据");
        for (String className : ParseEasycopyMetaDataStrategyHandler.interfaceMetaDataMap.keySet() ) {
            System.out.println("开始处理className");
            //处理方法元数据
             solveMethodDefinition(className);
            for (MethodMeta methodMeta : ParseEasycopyMetaDataStrategyHandler.interfaceMetaDataMap.get(className).values() ) {
                //处理注解参数元数据
                solvePropertyMappingDefinition(methodMeta);
            }
        }
        System.out.println("====================END========================");
    }
}
